package com.uqbar.game.stateSpacecraft;

import java.util.List;

import com.uqbar.game.Bullet;
import com.uqbar.game.Spacecraft;
import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Sprite;
import com.uqbar.vainilla.events.constants.Key;

public abstract class StateSpacecraft {
	
	protected Spacecraft spacecraft;
	protected double movX, movY;
	
	public StateSpacecraft(Spacecraft spacecraft){
		this.spacecraft = spacecraft;
		this.movX = this.spacecraft.getMovX();
		this.movY = this.spacecraft.getMovY();
	} 
	
	protected void move(DeltaState deltaState) {

		movX = this.spacecraft.getDiameter()*Math.cos(this.spacecraft.getAngle());
		movY = this.spacecraft.getDiameter()*Math.sin(this.spacecraft.getAngle());
		
		if(deltaState.isKeyBeingHold(Key.W) && (this.spacecraft.getSpeed()< this.spacecraft.getMaxSpeed())){
			this.spacecraft.setSpeed(this.spacecraft.getSpeed() + this.spacecraft.getAceleracion()* deltaState.getDelta());
			this.spacecraft.move(movX*this.spacecraft.getSpeed(), movY*this.spacecraft.getSpeed());
		}else{
			if(this.spacecraft.getSpeed() >0){
				this.spacecraft.setSpeed(this.spacecraft.getSpeed() + (-this.spacecraft.getAceleracion()) * deltaState.getDelta());
				this.spacecraft.move(movX*this.spacecraft.getSpeed(), movY*this.spacecraft.getSpeed());
			}
		}
	}
	
	protected void rotateSpacraft(DeltaState deltaState) {
		if(deltaState.isKeyBeingHold(Key.A)){
			this.spacecraft.setAngle(this.spacecraft.getAngle()- 0.1);
			this.spacecraft.rotate(deltaState);
//			this.spacecraft.getCurrentSpacecraft().rotate(Math.toRadians(this.spacecraft.getAngle()));
//			this.spacecraft.setAppearance(this.spacecraft.getCurrentSpacecraft());
		}
		if(deltaState.isKeyBeingHold(Key.D)){
			this.spacecraft.setAngle(this.spacecraft.getAngle()+ 0.1);
			this.spacecraft.rotate(deltaState);
//			this.spacecraft.getCurrentSpacecraft().rotate(Math.toRadians(this.spacecraft.getAngle()));
//			this.spacecraft.setAppearance(this.spacecraft.getCurrentSpacecraft());
		}
	}	
	
	public abstract void moveSpacecraft(DeltaState deltaState);

	public abstract Sprite getImage();

	public abstract List<Bullet> getBullets();

}
